/*
 * Created by JFormDesigner on Sun Nov 10 17:25:11 CST 2024
 */

package com.ch14;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author jjchen
 */
public class mylogin extends JFrame {
    public mylogin() {
        this.initComponents();

    }

    private void button1MousePressed(MouseEvent e) {
        // TODO add your code here
    }

    private void button1MouseClicked(MouseEvent e) {

        if(username.getText()!=null && !username.getText().isEmpty()){
            Home1 home = new Home1(username.getText());
            // 针对Home对象进行一些别的初始化
            home.setVisible(true);
            this.setVisible(false);
        }else{
            JOptionPane.showConfirmDialog(button1,"用户名不能为空");
        }
//            Home1 h = new Home1();
//            h.setVisible(true);

    }

    private void button2KeyPressed(KeyEvent e) {
        // TODO add your code here
    }

    private void button2MouseClicked(MouseEvent e) {
        regirter reg = new regirter();
        reg.setVisible(true);
        this.setVisible(false);
    }



    private void initComponents() {

        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        button1 = new JButton();
        passwordField1 = new JPasswordField();
        username = new JTextField();
        button2 = new JButton();
        label4 = new JLabel();

        //======== this ========
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("G2 group");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getStyle() | Font.BOLD, label1.getFont().getSize() + 9f));
        label1.setDisplayedMnemonicIndex(1);
        label1.setForeground(new Color(0x060210));
        contentPane.add(label1);
        label1.setBounds(170, 0, 135, 65);

        //---- label2 ----
        label2.setText("\u8d26\u6237");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getStyle() | Font.BOLD, label2.getFont().getSize() + 2f));
        contentPane.add(label2);
        label2.setBounds(100, 80, 75, 35);

        //---- label3 ----
        label3.setText("\u5bc6\u7801");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getStyle() | Font.BOLD, label3.getFont().getSize() + 2f));
        contentPane.add(label3);
        label3.setBounds(100, 120, 75, 35);

        //---- button1 ----
        button1.setText("\u767b\u5f55");
        button1.setBackground(Color.black);
        button1.setForeground(Color.white);
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
            @Override
            public void mousePressed(MouseEvent e) {
                button1MousePressed(e);
                button1MousePressed(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(155, 185, 130, 40);
        contentPane.add(passwordField1);
        passwordField1.setBounds(150, 120, 135, 35);
        contentPane.add(username);
        username.setBounds(150, 80, 135, 35);

        //---- button2 ----
        button2.setText("\u6ce8\u518c");
        button2.setBackground(Color.black);
        button2.setForeground(new Color(0xcccccc));
        button2.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                button2KeyPressed(e);
            }
        });
        button2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button2MouseClicked(e);
            }
        });
        contentPane.add(button2);
        button2.setBounds(180, 235, 75, 30);

        //---- label4 ----
        label4.setText("text");
        label4.setIcon(new ImageIcon(getClass().getResource("/com/th.jpg")));
        contentPane.add(label4);
        label4.setBounds(-10, -65, 435, 390);

        contentPane.setPreferredSize(new Dimension(430, 325));
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on

        setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }


    public static void main(String[] args) {
        mylogin login = new mylogin();
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JButton button1;
    private JPasswordField passwordField1;
    private JTextField username;
    private JButton button2;
    private JLabel label4;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}



